package cn.stylefeng.guns.modular.basic.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.basic.entity.BasicLoadUnloadLabor;
import cn.stylefeng.guns.modular.basic.mapper.BasicLoadUnloadLaborMapper;
import cn.stylefeng.guns.modular.basic.model.params.BasicLoadUnloadLaborParam;
import cn.stylefeng.guns.modular.basic.model.result.BasicLoadUnloadLaborResult;
import  cn.stylefeng.guns.modular.basic.service.BasicLoadUnloadLaborService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 装卸工劳务公司 服务实现类
 * </p>
 *
 * @author zhangzh
 * @since 2024-07-18
 */
@Service
public class BasicLoadUnloadLaborServiceImpl extends ServiceImpl<BasicLoadUnloadLaborMapper, BasicLoadUnloadLabor> implements BasicLoadUnloadLaborService {

    @Override
    public void add(BasicLoadUnloadLaborParam param){
        BasicLoadUnloadLabor entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BasicLoadUnloadLaborParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(BasicLoadUnloadLaborParam param){
        BasicLoadUnloadLabor oldEntity = getOldEntity(param);
        BasicLoadUnloadLabor newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BasicLoadUnloadLaborResult findBySpec(BasicLoadUnloadLaborParam param){
        return null;
    }

    @Override
    public List<BasicLoadUnloadLaborResult> findListBySpec(BasicLoadUnloadLaborParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(BasicLoadUnloadLaborParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public int selectCountByCode(BasicLoadUnloadLaborParam paramCondition) {
        return this.baseMapper.selectCountByCode(paramCondition);
    }

    @Override
    public int selectCountByPrefix(BasicLoadUnloadLaborParam paramCondition) {
        return this.baseMapper.selectCountByPrefix(paramCondition);
    }

    private Serializable getKey(BasicLoadUnloadLaborParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BasicLoadUnloadLabor getOldEntity(BasicLoadUnloadLaborParam param) {
        return this.getById(getKey(param));
    }

    private BasicLoadUnloadLabor getEntity(BasicLoadUnloadLaborParam param) {
        BasicLoadUnloadLabor entity = new BasicLoadUnloadLabor();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
